package 反射.代理;

/**
 * @Projectname java_based
 * @Filename StaticProxyTest
 * @Author an
 * @Data 2022/7/27 20:33
 * @Description TODO
 */

/*
* 静态代理举例
*
* 特点：代理类和被代理类在编译期间就确定下来了
* */
interface ClothFactory{
    void productCloth();
}

//代理类
class ProClothFactory implements ClothFactory {

    private ClothFactory factory;//用被代理类对象进行实例化

    public ProClothFactory(ClothFactory factory) {
        this.factory = factory;
    }

    @Override
    public void productCloth() {
        System.out.println("代理工厂做一些准备工作");

        factory.productCloth();
        System.out.println("代理工厂做一些后续的收尾工作");
    }
}


//被代理类
class NickClothFactory implements ClothFactory{

    @Override
    public void productCloth() {
        System.out.println("Nick工厂生产一批运动服");
    }
}

public class StaticProxyTest {

    public static  void main(String[] args) {
        //创建代理类对象
        ClothFactory nick = new NickClothFactory();
        //创建被代理类对象
        ProClothFactory proxy = new ProClothFactory(nick);
        proxy.productCloth();

    }
}